﻿using System;
using PS_WSSDeploy_Package.Application;
using PS_WSSDeploy_Package.Utils;

namespace PS_WSSDeploy_Package.WdCommand
{
    class DeployCmd : BaseCmd, IWdTask
    {
        public override void DoExecute()
        {
            AddTask(this);
        }

        public void TaskExecute()
        {
            try
            {
                Cc.Deploy(WSPFullFileName, ProjectTargetFolder);
                WriteOutput(string.Format(WssDeployResources.DeployFullCmd_DeploySolutionSucceeded, WSPFileName));
                SetSuccess();
            }
            catch(ApplicationException ex)
            {
                WriteOutput(string.Format(WssDeployResources.DeployFullCmd_DeploySolutionError, WSPFileName, ex.Message));
                SetFailed();              
            }
            catch (Exception ex)
            {
                WriteOutput(string.Format(WssDeployResources.DeployFullCmd_DeploySolutionError, WSPFileName, ex.Message));
                SetFailed();
            }
        }
    }
}
